#pragma once
#include<iostream>
#include<algorithm>
#include<string.h>
#include<assert.h>
using namespace std;

namespace xhy
{
	class string
	{
	public:
		typedef char* iterator;
		string(const char* str = "");
		string(const string& s);
		string& operator=(string s);
		~string();

		size_t size() const;
		size_t capacity()const;
		bool empty()const;

		void swap(string& s);
		char& operator[](size_t pos);
		const char& operator[](size_t pos) const;

		const char* c_str() const;

		iterator begin();
		iterator end();


		void resize(size_t n, char c = '\0');
		void reserve(size_t n = 0);
		void push_back(char ch);
		string& append(const char* str);
		string&  operator+=(char ch);
		string&  operator+=(const char* str);
		string& insert(size_t pos, char c);
		string& insert(size_t pos, const char* str);

		void pop_back();
		string& erase(size_t pos = 0, size_t len = npos);
		void clear();

		size_t find(char ch, size_t pos = 0) const;
		size_t find(const char* str, size_t pos = 0) const;
		string substr(size_t pos = 0, size_t len = npos) const;

		bool operator<(const string& s) const;
		bool operator<=(const string& s) const;
		bool operator>(const string& s) const;
		bool operator>=(const string& s) const;
		bool operator==(const string& s) const;
		bool operator!=(const string& s) const;

	private:
		char* _str = nullptr;
		size_t _size = 0;
		size_t _capacity = 0;

	public:
		const static size_t npos;
	};

	std::ostream& operator<<(std::ostream& out, const string& str);
	std::istream& operator>>(std::istream& in, string& str);
	std::istream& getline(std::istream& in, string& str, char delim = '\n');
}